﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SalesSys.DAL.Models;

namespace SalesSys.BLL
{
    public class NonstandardDiscountBLL : BaseBLL<NonstandardDiscount>
    {
        /// <summary>
        /// 计算优惠
        /// </summary>
        /// <param name="commodityInfos">总优惠，及计算说明文本</param>
        /// <returns></returns>
        public Tuple<decimal, string> CalcDiscount(IEnumerable<CommodityInfo> commodityInfos)
        {
            decimal sum = 0;
            var msg = "";
            foreach (var commodityInfo in commodityInfos)
            {
                var depotId = Guid.Empty;//commodityInfo.Order.Depot.Id; todo..
                var sup = commodityInfo.Commodity.Supplier.Id;
                var dis = Details(new Object[] { sup, depotId });
                var all = commodityInfo.Weight * dis.Discount;
                sum += all;
                msg += string.Format("商品{0}优惠{1},", commodityInfo.Commodity.FillName(), all);
            }
            msg = msg + "共优惠" + sum;
            return Tuple.Create(sum, msg);
        }
    }
}
